package wsem.parser;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Vector;

import wsem.model.Qrel;
import wsem.utils.ConfigUtils;

public class QrelParser {
	
	private Vector<Qrel> listeElement;

    private final String INPUT_DIRECTORY = ConfigUtils.PATH_QRELS;

    public QrelParser() {
            listeElement = new Vector<Qrel>();
    }


    public Vector<Qrel> getListeElement() {
            return listeElement;
    }

 
    public Vector<Qrel> parseQrel(String filename) throws Exception {
         
            try {
                    InputStream ips = new FileInputStream(INPUT_DIRECTORY
                                     + "qrel"
                                    + filename.substring(1) + ".txt");
                    InputStreamReader ipsr = new InputStreamReader(ips);
                    BufferedReader br = new BufferedReader(ipsr);

                    String ligne;
                    String[] ligneTab;
                    
                    listeElement.clear();
                    while ((ligne = br.readLine()) != null) {
                            ligneTab = ligne.split("\t");
                            listeElement.add(new Qrel(filename,ligneTab[0].substring("Collection/".length()),
                                            ligneTab[1], Integer.valueOf(ligneTab[2])));
                            
                    }
                    br.close();
            } catch (Exception e) {
                    System.out.println("Lecture qrel failed");
                    throw e;
            }
            return listeElement;
    }

}
